import Cookies from 'js-cookie'

const TokenKey = 'vue_admin_template_token'

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

/**
 * 放在cookie中比 sessionStorage 中好，sessionStorage 不能在多标签中公用
 * 但在iframe中，chrome浏览器在请求时不会携带cookie
 */
export function getAppId() {
  return Cookies.get('AppId')
}

export function getAuthorization() {
  return Cookies.get('Authorization')
}

export function setAppId(data) {
  return Cookies.set('AppId', data)
}

export function setAuthorization(data) {
  return Cookies.set('Authorization', data)
}

export function clearAuthInfo() {
  sessionStorage.clear()
  Cookies.remove('AppId')
  Cookies.remove('Authorization')
}
